﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace FrameWork.UI.UserControls
{
    [System.ComponentModel.DesignTimeVisible(false)]//在工具箱中 隐藏该窗体 
    /// <summary>
    /// THourView.xaml 的交互逻辑
    /// </summary>
    public partial class THourView : UserControl
    {
    

        string formerHourStr { get;   set; }

        public THourView()
        {
            InitializeComponent();
        }
         /// <summary>
          /// 构造函数
          /// </summary>
          /// <param name="txt"></param>
          public THourView(string txt)

        {
            InitializeComponent();
            this.formerHourStr = txt;
          }
        private void iBtnCloseView_Click(object sender, RoutedEventArgs e)
        {
            OnHourClickContentEdit(this.formerHourStr);
        }

        private void dgHour_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            DataGridCellInfo cell = dgHour.CurrentCell;
            if (cell.Column==null)
            {
                return;
            }
            Hour hour= cell.Item as Hour;

            string str1=string.Empty;
            switch (cell.Column.DisplayIndex)
            {
                case 0:
                    str1 = hour.Hour1.ToString();
                    break;

                case 1:
                    str1 = hour.Hour2.ToString();
                    break;

                case 2:
                    str1 = hour.Hour3.ToString();
                    break;

                case 3:
                    str1 = hour.Hour4.ToString();
                    break;

                case 4:
                    str1 = hour.Hour5.ToString();
                    break;

                case 5:
                    str1 = hour.Hour6.ToString();
                    break;

                default: break;
            }

            str1 = str1.PadLeft(2, '0');
            OnHourClickContentEdit(str1);
        }
        public Action<string> HourClick;
        private void OnHourClickContentEdit(string hourstr)
        {
            if (HourClick != null)
                  HourClick(hourstr);
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            LoadHours();
        }

        private void LoadHours()
        {
            Hour[] hours = new Hour[4];
            hours[0] = new Hour(0,  1,  2,  3,  4,  5);
            hours[1] = new Hour(6,  7,  8,  9,  10, 11 );
            hours[2] = new Hour(12, 13, 14, 15, 16, 17);
            hours[3] = new Hour(18, 19, 20, 21, 22, 23 );
            dgHour.Items.Clear();
            dgHour.ItemsSource = hours;
        }
    }
}
